using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace TimeWar
{
    public class SceneCamera : Camera
    {
        private Vector3 thirdPersonReference = new Vector3(0, 200, -200);

        public SceneCamera() : base()
        {
        }

        protected void updateView(Quaternion objRotation, Vector3 objPosition)
        {

            Matrix rotationMatrix = Matrix.CreateRotationY(objRotation.W);
            Vector3 transformedReference = Vector3.Transform(thirdPersonReference, rotationMatrix);
            position = transformedReference + objPosition;
            view = Matrix.CreateLookAt(position, Vector3.Zero, Vector3.Forward);
            projection = Matrix.CreatePerspectiveFieldOfView(viewAngle, aspectRatio, nearClip, farClip);
            updateFrustrum();
        }

        public override void Update(Vector3 objPosition, Quaternion objRotation)
        {
            if (XInputHelper.GamePads[PlayerIndex.One].ThumbStickRightY < 0)
            {
                position.Z += 100;
            }
            else if (XInputHelper.GamePads[PlayerIndex.One].ThumbStickRightY > 0)
            {
                position.Z -= 100;
            }

            if (XInputHelper.GamePads[PlayerIndex.One].ThumbStickRightX < 0)
            {
                position.X += 100;
            }
            else if (XInputHelper.GamePads[PlayerIndex.One].ThumbStickRightX > 0)
            {
                position.X -= 100;
            }

            updateView(objRotation, objPosition);


        }

    }
}